<?php
namespace app\manager\controller;
use \think\Controller;
use think\Request;
use think\Session;
class Card extends Controller
{

	public function getIndex()
	{
		$card_list = model('Cards')->getCardLists(input('get.'));
		$this->assign('card_list',$card_list);
		return view('p/card/index');
	}

	public function getAddCard($id)
	{
		$caravan_info = model('Caravans')->getCaravanInfo($id);
		$this->assign('caravan_info',$caravan_info);
		$this->assign('id',$id);
		return view('p/card/add');
	}

	public function getCardInfo($id)
	{
		$card_info = model('Cards')->getCardInfo($id);//halt($card_info);
		$this->assign('card_info',$card_info);
		return view('p/card/card');
	}

	public function postAddCard()
	{
		$id = session('manager.id');
        $camp_id = model('CampManagers')->where('id',$id)->value('camp_id');
        $post_card_info['camp_id'] = $camp_id;
		$post_card_info['card_num'] = model("user/CaravanInfos")->quickRandom(12);
		if (input('post.contract_num') == '' || input('post.user_phone') == '') {
			return $this->error('请填写合同号或手机号');
		}
		$contract_num = model('Cards')->where('contract_num',input('post.contract_num'))->find();
		if ($contract_num) {
			return $this->error('该合同号已存在,请重新填写');
		}
		$post_card_info['contract_num'] = input('post.contract_num');
		$post_card_info['user_phone'] = input('post.user_phone');
		$post_card_info['caravan_id'] = input('post.caravan_id');

		$card = model('Cards')->createCards($post_card_info);
		if ($card) {
			return $this->success('生成卡号成功', '/card/index');
		}
			return $this->error('生成卡号失败');

	}
}